from datetime import datetime, timedelta, timezone
import pytest
from common.request_util_test import RequestUtil
from common.test_yaml_util_test import YamlUtil
from config import datas


class Testmonitoring:
    url_unify = "/clusters/host"
    search_time = str(datetime.now(tz=timezone.utc)).split('.')[0]
    starttime = str(datetime.now(tz=timezone.utc) - timedelta(minutes=10)).split('.')[0]
    endtime = str(datetime.now(tz=timezone.utc)).split('.')[0]

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/1_get_cluster_metric.yaml'))
    def test_get_cluster_metric(self, monitoringinfo):
        # 查询集群级别的指标数据-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        if '{time}' in monitoringinfo['request']['url']:
            url = base_url + monitoringinfo['request']['url'].replace('{time}', Testmonitoring.search_time)
        else:
            url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/1_get_cluster_metric_exception.yaml'))
    def test_get_cluster_metric_exception(self, monitoringinfo):
        # 查询集群级别的指标数据-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        if '{time}' in monitoringinfo['request']['url']:
            url = base_url + monitoringinfo['request']['url'].replace('{time}', Testmonitoring.search_time)
        else:
            url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/1_get_cluster_metrics_range_vector.yaml'))
    def test_get_cluster_metrics_range_vector(self, monitoringinfo):
        # 查询集群级别的指标数据-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'starttime': Testmonitoring.starttime, 'endtime': Testmonitoring.endtime,
                        'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/1_get_cluster_metrics_range_vector_exception.yaml'))
    def test_get_cluster_metrics_range_vector_exception(self, monitoringinfo):
        # 查询集群级别的指标数据-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'starttime': Testmonitoring.starttime, 'endtime': Testmonitoring.endtime,
                        'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/2_get_node_metric.yaml'))
    def test_get_node_metric(self, monitoringinfo):
        # 查询节点级别的指标数据-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url'].replace('{nodename}', datas.HOST_NAME)
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/2_get_node_metric_exception.yaml'))
    def test_get_node_metric_exception(self, monitoringinfo):
        # 查询节点级别的指标数据-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url'].replace('{nodename}', datas.HOST_NAME)
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/2_get_node_metric_range_vector.yaml'))
    def test_get_node_metrics_range_vector(self, monitoringinfo):
        # 查询节点级别的指标数据-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'nodename': datas.HOST_NAME, 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/2_get_node_metric_range_vector_exception.yaml'))
    def test_get_node_metrics_range_vector_exception(self, monitoringinfo):
        # 查询节点级别的指标数据-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'nodename': datas.HOST_NAME, 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/3_get_workload_metric_deployment.yaml'))
    def test_get_workload_metric_deployment(self, monitoringinfo):
        # 查询工作负载的指标数据-deployment-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'deployment': urlinfo['deployment'],
                        'podname': urlinfo['podname'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/3_get_workload_metric_deployment_exception.yaml'))
    def test_get_workload_metric_deployment_exception(self, monitoringinfo):
        # 查询工作负载的指标数据-deployment-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'deployment': urlinfo['deployment'],
                        'podname': urlinfo['podname'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/3_get_workload_metric_range_vector_deployment.yaml'))
    def test_get_workload_metric_range_vector_deployment(self, monitoringinfo):
        # 查询工作负载的指标数据-deployment-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'deployment': urlinfo['deployment'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/3_get_workload_metric_range_vector_deployment_exception.yaml'))
    def test_get_workload_metric_range_vector_deployment_exception(self, monitoringinfo):
        # 查询工作负载的指标数据-deployment-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'deployment': urlinfo['deployment'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/4_get_workload_metric_statefulset.yaml'))
    def test_get_workload_metric_statefulset(self, monitoringinfo):
        # 查询工作负载的指标数据-statefulset-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'statefulset': urlinfo['statefulset'],
                        'podname': urlinfo['podname'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/4_get_workload_metric_statefulset_exception.yaml'))
    def test_get_workload_metric_statefulset_exception(self, monitoringinfo):
        # 查询工作负载的指标数据-statefulset-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'statefulset': urlinfo['statefulset'],
                        'podname': urlinfo['podname'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/4_get_workload_metric_range_vector_statefulset.yaml'))
    def test_get_workload_metric_range_vector_statefulset(self, monitoringinfo):
        # 查询工作负载的指标数据-statefulset-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'statefulset': urlinfo['statefulset'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/4_get_workload_metric_range_vector_statefulset_exception.yaml'))
    def test_get_workload_metric_range_vector_statefulset_exception(self, monitoringinfo):
        # 查询工作负载的指标数据-statefulset-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'statefulset': urlinfo['statefulset'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/5_get_workload_metric_daemonset.yaml'))
    def test_get_workload_metric_daemonset(self, monitoringinfo):
        # 查询工作负载的指标数据-daemonset-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'daemonset': urlinfo['daemonset'],
                        'podname': urlinfo['podname'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/5_get_workload_metric_daemonset_exception.yaml'))
    def test_get_workload_metric_daemonset_exception(self, monitoringinfo):
        # 查询工作负载的指标数据-daemonset-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'daemonset': urlinfo['daemonset'],
                        'podname': urlinfo['podname'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/5_get_workload_metric_range_vector_daemonset.yaml'))
    def test_get_workload_metric_range_vector_daemonset(self, monitoringinfo):
        # 查询工作负载的指标数据-daemonset-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'daemonset': urlinfo['daemonset'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/5_get_workload_metric_range_vector_daemonset_exception.yaml'))
    def test_get_workload_metric_range_vector_daemonset_exception(self, monitoringinfo):
        # 查询工作负载的指标数据-daemonset-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'daemonset': urlinfo['daemonset'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml('v25.06/monitoring/6_get_pod_metric.yaml'))
    def test_get_pod_metric(self, monitoringinfo):
        # 查询pod级别的指标数据-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/6_get_pod_metric_exception.yaml'))
    def test_get_pod_metric_exception(self, monitoringinfo):
        # 查询pod级别的指标数据-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/6_get_pod_metric_range_vector.yaml'))
    def test_get_pod_metric_range_vector(self, monitoringinfo):
        # 查询pod级别的指标数据-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/6_get_pod_metric_range_vector_exception.yaml'))
    def test_get_pod_metric_range_vecto_exceptionr(self, monitoringinfo):
        # 查询pod级别的指标数据-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/7_get_container_metric.yaml'))
    def test_get_container_metric(self, monitoringinfo):
        # 查询container级别的指标数据-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'containername': urlinfo['containername'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/7_get_container_metric_exception.yaml'))
    def test_get_container_metric_exception(self, monitoringinfo):
        # 查询container级别的指标数据-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'containername': urlinfo['containername'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/7_get_container_metric_range_vector.yaml'))
    def test_get_container_metric_range_vector(self, monitoringinfo):
        # 查询container级别的指标数据-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'containername': urlinfo['containername'], 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/7_get_container_metric_range_vector_exception.yaml'))
    def test_get_container_metric_range_vector_exception(self, monitoringinfo):
        # 查询container级别的指标数据-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'namespace': urlinfo['namespace'], 'podname': urlinfo['podname'],
                        'containername': urlinfo['containername'], 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/8_get_control_plane_metric_kubeapiserver.yaml'))
    def test_get_control_plane_metric_kubeapiserver(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-apiserver-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        replacements = {'component': 'kube-apiserver', 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/8_get_control_plane_metric_kubeapiserver_exception.yaml'))
    def test_get_control_plane_metric_kubeapiserver_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-apiserver-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        replacements = {'component': 'kube-apiserver', 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/8_get_control_plane_metric_range_vector_kubeapiserver.yaml'))
    def test_get_control_plane_metric_range_vector_kubeapiserver(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-apiserver-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-apiserver', 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/8_get_control_plane_metric_range_vector_kubeapiserver_exception.yaml'))
    def test_get_control_plane_metric_range_vector_kubeapiserver_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-apiserver-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-apiserver', 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/9_get_control_plane_metric_etcd.yaml'))
    def test_get_control_plane_metric_etcd(self, monitoringinfo):
        # 查询控制平面组件的指标数据-etcd-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'etcd', 'instance': urlinfo['etcd_instance'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/9_get_control_plane_metric_etcd_exception.yaml'))
    def test_get_control_plane_metric_etcd_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-etcd-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'etcd', 'instance': urlinfo['etcd_instance'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/9_get_control_plane_metric_range_vector_etcd.yaml'))
    def test_get_control_plane_metric_range_vector_etcd(self, monitoringinfo):
        # 查询控制平面组件的指标数据-etcd-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'etcd', 'instance': urlinfo['etcd_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/9_get_control_plane_metric_range_vector_etcd_exception.yaml'))
    def test_get_control_plane_metric_range_vector_etcd_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-etcd-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'etcd', 'instance': urlinfo['etcd_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/10_get_control_plane_metric_kubescheduler.yaml'))
    def test_get_control_plane_metric_kubescheduler(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kubescheduler-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-scheduler', 'instance': urlinfo['kube_scheduler_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/10_get_control_plane_metric_kubescheduler_exception.yaml'))
    def test_get_control_plane_metric_kubescheduler_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kubescheduler-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-scheduler', 'instance': urlinfo['kube_scheduler_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/10_get_control_plane_metric_range_vector_kubescheduler.yaml'))
    def test_get_control_plane_metric_range_vector_kubescheduler(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-scheduler-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-scheduler', 'instance': urlinfo['kube_scheduler_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/10_get_control_plane_metric_range_vector_kubescheduler_exception.yaml'))
    def test_get_control_plane_metric_range_vector_kubescheduler_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-scheduler-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-scheduler', 'instance': urlinfo['kube_scheduler_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/11_get_control_plane_metric_kubecontrollermanager.yaml'))
    def test_get_control_plane_metric_kubecontrollermanager(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-controller-manager-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-controller-manager', 'instance': urlinfo['kube_controller_manager_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/11_get_control_plane_metric_kubecontrollermanager_exception.yaml'))
    def test_get_control_plane_metric_kubecontrollermanager_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-controller-manager-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-controller-manager', 'instance': urlinfo['kube_controller_manager_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/11_get_control_plane_metric_range_vector_kubecontrollermanager.yaml'))
    def test_get_control_plane_metric_range_vector_kubecontrollermanager(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-controller-manager-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-controller-manager', 'instance': urlinfo['kube_controller_manager_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/11_get_control_plane_metric_range_vector_kubecontrollermanager_exception.yaml'))
    def test_get_control_plane_metric_range_vector_kubecontrollermanager_exception(self, monitoringinfo):
        # 查询控制平面组件的指标数据-kube-controller-manager-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-controller-manager', 'instance': urlinfo['kube_controller_manager_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/12_get_node_component_metric_kubelet.yaml'))
    def test_get_node_component_metric_kubelet(self, monitoringinfo):
        # 查询节点组件的指标数据-kubelet-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kubelet', 'instance': urlinfo['kubelet_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/12_get_node_component_metric_kubelet_exception.yaml'))
    def test_get_node_component_metric_kubelet_exception(self, monitoringinfo):
        # 查询节点组件的指标数据-kubelet-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kubelet', 'instance': urlinfo['kubelet_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/12_get_node_component_metric_range_vector_kubelet.yaml'))
    def test_get_node_component_metric_range_vector_kubelet(self, monitoringinfo):
        # 查询节点组件的指标数据-kubelet-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kubelet', 'instance': urlinfo['kubelet_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/12_get_node_component_metric_range_vector_kubelet_exception.yaml'))
    def test_get_node_component_metric_range_vector_kubelet_exception(self, monitoringinfo):
        # 查询节点组件的指标数据-kubelet-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kubelet', 'instance': urlinfo['kubelet_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/13_get_node_component_metric_kubeproxy.yaml'))
    def test_get_node_component_metric_kubeproxy(self, monitoringinfo):
        # 查询节点组件的指标数据-kube-proxy-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-proxy', 'instance': urlinfo['kube_proxy_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/13_get_node_component_metric_kubeproxy_exception.yaml'))
    def test_get_node_component_metric_kubeproxy_exception(self, monitoringinfo):
        # 查询节点组件的指标数据-kube-proxy-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-proxy', 'instance': urlinfo['kube_proxy_instance'],
                        'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/13_get_node_component_metric_range_vector_kubeproxy.yaml'))
    def test_get_node_component_metric_range_vector_kubeproxy(self, monitoringinfo):
        # 查询节点组件的指标数据-kube-proxy-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-proxy', 'instance': urlinfo['kube_proxy_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/13_get_node_component_metric_range_vector_kubeproxy.yaml'))
    def test_get_node_component_metric_range_vector_kubeproxy(self, monitoringinfo):
        # 查询节点组件的指标数据-kube-proxy-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'component': 'kube-proxy', 'instance': urlinfo['kube_proxy_instance'],
                        'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/14_get_addon_component_metric.yaml'))
    def test_get_addon_component_metric(self, monitoringinfo):
        # 查询addon组件的指标数据-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'instance': urlinfo['addon_instance'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/14_get_addon_component_metric_exception.yaml'))
    def test_get_addon_component_metric_exception(self, monitoringinfo):
        # 查询addon组件的指标数据-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'instance': urlinfo['addon_instance'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/14_get_addon_component_metric_range_vector.yaml'))
    def test_get_addon_component_metric_range_vector(self, monitoringinfo):
        # 查询addon组件的指标数据-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'instance': urlinfo['addon_instance'], 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/14_get_addon_component_metric_range_vector_exception.yaml'))
    def test_get_addon_component_metric_range_vector_exception(self, monitoringinfo):
        # 查询addon组件的指标数据-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'instance': urlinfo['addon_instance'], 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/15_get_user_promql.yaml'))
    def test_get_user_promql(self, monitoringinfo):
        # 用户自定义表达式查询-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'expr': urlinfo['expr'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/15_get_user_promql_exception.yaml'))
    def test_get_user_promql_exception(self, monitoringinfo):
        # 用户自定义表达式查询-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'expr': urlinfo['expr'], 'time': Testmonitoring.search_time}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/15_get_user_promql_range_vector.yaml'))
    def test_get_user_promql_range_vector(self, monitoringinfo):
        # 用户自定义表达式查询-范围向量-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'expr': urlinfo['expr'], 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo', YamlUtil().read_testcase_yaml(
        'v25.06/monitoring/15_get_user_promql_range_vector_exception.yaml'))
    def test_get_user_promql_range_vector_exception(self, monitoringinfo):
        # 用户自定义表达式查询-范围向量-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        urlinfo = datas.test_monitoring
        replacements = {'expr': urlinfo['expr'], 'starttime': Testmonitoring.starttime,
                        'endtime': Testmonitoring.endtime, 'steptime': urlinfo['steptime']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/16_get_targets_list.yaml'))
    def test_get_targets_list(self, monitoringinfo):
        # 获取监控目标列表-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/16_get_targets_list_exception.yaml'))
    def test_get_targets_list_exception(self, monitoringinfo):
        # 获取监控目标列表-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/17_get_monitoring_servicemonitor.yaml'))
    def test_get_monitoring_servicemonitor(self, monitoringinfo):
        # 获取monitoring ServiceMonitor列表
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/17_create_servicemonitor.yaml'))
    def test_create_servicemonitor(self, monitoringinfo):
        # 创建ServiceMonitor
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url'].replace('{namespace}', 'monitoring')
        method = monitoringinfo['request']['method']
        data = monitoringinfo['request']['data']
        req = RequestUtil().send_request(method, url, json=data)
        servicemonitorname = req.json()['metadata']['name']
        globals()['servicemonitorname'] = servicemonitorname
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/17_get_servicemonitor_list.yaml'))
    def test_get_servicemonitor_list(self, monitoringinfo):
        # 获取ServiceMonitor列表
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/17_get_specific_servicemonitor.yaml'))
    def test_get_specific_servicemonitor(self, monitoringinfo):
        # 获取指定的ServiceMonitor
        base_url = datas.baseUrl + Testmonitoring.url_unify
        replacements = {'namespace': 'monitoring', 'servicemonitorname': globals()['servicemonitorname']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        globals()['updatereqbody'] = req.json()
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/17_update_servicemonitor.yaml'))
    def test_update_servicemonitor(self, monitoringinfo):
        # 更新指定ServiceMonitor接口
        base_url = datas.baseUrl + Testmonitoring.url_unify
        replacements = {'namespace': 'monitoring', 'servicemonitorname': globals()['servicemonitorname']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        monitoringinfo['request']['data'] = globals()['updatereqbody']
        data = monitoringinfo['request']['data']
        req = RequestUtil().send_request(method, url, json=data)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/17_update_section_servicemonitor.yaml'))
    def test_update_section_servicemonitor(self, monitoringinfo):
        # 部分更新指定ServiceMonitor接口
        base_url = datas.baseUrl + Testmonitoring.url_unify
        replacements = {'namespace': 'monitoring', 'servicemonitorname': globals()['servicemonitorname']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        data = monitoringinfo['request']['data']
        header = monitoringinfo['request']['headers']
        req = RequestUtil().send_request(method, url, json=data, headers=header)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/17_delete_specific_servicemonitor.yaml'))
    def test_delete_specific_servicemonitor(self, monitoringinfo):
        # 删除指定ServiceMonitor接口
        base_url = datas.baseUrl + Testmonitoring.url_unify
        replacements = {'namespace': 'monitoring', 'servicemonitorname': globals()['servicemonitorname']}
        url = base_url + f"{monitoringinfo['request']['url'].format_map(replacements)}"
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.normal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/18_get_alert_rule_list.yaml'))
    def test_get_alert_rule_list(self, monitoringinfo):
        # 获取告警规则列表-正常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']

    @pytest.mark.abnormal
    @pytest.mark.monitoring
    @pytest.mark.parametrize('monitoringinfo',
                             YamlUtil().read_testcase_yaml('v25.06/monitoring/18_get_alert_rule_list_exception.yaml'))
    def test_get_alert_rule_list_exception(self, monitoringinfo):
        # 获取告警规则列表-异常
        base_url = datas.baseUrl + Testmonitoring.url_unify
        url = base_url + monitoringinfo['request']['url']
        method = monitoringinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        assert req.status_code == monitoringinfo['validate'][0]['equals']['status_code']
